<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">


<link rel="stylesheet" href="/blog/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"dttx123.gitee.io","root":"/blog/","scheme":"Gemini","version":"8.0.0-rc.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="jQuery基本介绍为什么要学jQuery使用JS操作DOM的时候，会遇到以下的一些缺点： 12345&#x2F;&#x2F;1. 获取元素的方法太少且长，麻烦。&#x2F;&#x2F;2. 遍历伪数组很麻烦，通常要嵌套一大堆的for循环。&#x2F;&#x2F;3. 注册的事件会覆盖。&#x2F;&#x2F;4. 有兼容性问题。&#x2F;&#x2F;5. 实现动画很麻烦">
<meta property="og:type" content="article">
<meta property="og:title" content="JQuery基础">
<meta property="og:url" content="http://dttx123.gitee.io/2017/05/05/JQuery/JQuery/index.html">
<meta property="og:site_name" content="Starry Night">
<meta property="og:description" content="jQuery基本介绍为什么要学jQuery使用JS操作DOM的时候，会遇到以下的一些缺点： 12345&#x2F;&#x2F;1. 获取元素的方法太少且长，麻烦。&#x2F;&#x2F;2. 遍历伪数组很麻烦，通常要嵌套一大堆的for循环。&#x2F;&#x2F;3. 注册的事件会覆盖。&#x2F;&#x2F;4. 有兼容性问题。&#x2F;&#x2F;5. 实现动画很麻烦">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://dttx123.gitee.io/blog/2017/05/05/JQuery/JQuery/1.png">
<meta property="article:published_time" content="2017-05-04T16:00:00.000Z">
<meta property="article:modified_time" content="2020-05-13T00:44:40.347Z">
<meta property="article:author" content="大春哥">
<meta property="article:tag" content="JQuery">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://dttx123.gitee.io/blog/2017/05/05/JQuery/JQuery/1.png">

<link rel="canonical" href="http://dttx123.gitee.io/2017/05/05/JQuery/JQuery/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>JQuery基础 | Starry Night</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line toggle-line-first"></span>
        <span class="toggle-line toggle-line-middle"></span>
        <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Starry Night</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">这就朕为你打下的江山</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://dttx123.gitee.io/2017/05/05/JQuery/JQuery/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.jpg">
      <meta itemprop="name" content="大春哥">
      <meta itemprop="description" content="IT">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Starry Night">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          JQuery基础
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2017-05-05 00:00:00" itemprop="dateCreated datePublished" datetime="2017-05-05T00:00:00+08:00">2017-05-05</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-13 08:44:40" itemprop="dateModified" datetime="2020-05-13T08:44:40+08:00">2020-05-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/JQuery/" itemprop="url" rel="index"><span itemprop="name">JQuery</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="jQuery基本介绍"><a href="#jQuery基本介绍" class="headerlink" title="jQuery基本介绍"></a>jQuery基本介绍</h1><h2 id="为什么要学jQuery"><a href="#为什么要学jQuery" class="headerlink" title="为什么要学jQuery"></a>为什么要学jQuery</h2><p>使用JS操作DOM的时候，会遇到以下的一些缺点：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1. 获取元素的方法太少且长，麻烦。</span></span><br><span class="line"><span class="comment">//2. 遍历伪数组很麻烦，通常要嵌套一大堆的for循环。</span></span><br><span class="line"><span class="comment">//3. 注册的事件会覆盖。</span></span><br><span class="line"><span class="comment">//4. 有兼容性问题。</span></span><br><span class="line"><span class="comment">//5. 实现动画很麻烦</span></span><br></pre></td></tr></table></figure>

<a id="more"></a>

<h2 id="jQuery初体验"><a href="#jQuery初体验" class="headerlink" title="jQuery初体验"></a>jQuery初体验</h2><p>【02-让div显示与设置内容.html】</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="built_in">document</span>).ready(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    $(<span class="string">"#btn1"</span>).click(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">      <span class="comment">// 隐式迭代：偷偷的遍历，在jQuery中，不需要手动写for循环了，会自动进行遍历。</span></span><br><span class="line">        $(<span class="string">"div"</span>).show(<span class="number">200</span>);</span><br><span class="line">    &#125;);</span><br><span class="line">    $(<span class="string">"#btn2"</span>).click(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">        $(<span class="string">"div"</span>).text(<span class="string">"我是内容"</span>);</span><br><span class="line">    &#125;);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>使用jQuery的优点</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1. 获取元素的方式非常的简单，而且非常的丰富</span></span><br><span class="line"><span class="comment">//2. jQuery的隐式迭代特性，不再需要书写for循环语句。</span></span><br><span class="line"><span class="comment">//3. 使用jQuery完全不用考虑兼容性问题。</span></span><br><span class="line"><span class="comment">//4. jQuery提供了一系列动画相关的函数，使用非常方便。</span></span><br><span class="line"><span class="comment">//5. 代码简单、粗暴。</span></span><br></pre></td></tr></table></figure>

<p><strong>没有对比，就没有伤害，有了对比，处处戳中要害。</strong></p>
<h2 id="什么是jQuery"><a href="#什么是jQuery" class="headerlink" title="什么是jQuery?"></a>什么是jQuery?</h2><blockquote>
<p>jQuery是一个快速的、轻量的、功能丰富的js库。</p>
</blockquote>
<p>jQuery的官网 <a href="http://jquery.com/" target="_blank" rel="noopener">http://jquery.com/</a> </p>
<p>jQuery就是一个js库，使用jQuery的话，会比使用JavaScript更简单。</p>
<p>js库：把一些常用到的方法写到一个单独的js文件，使用的时候直接去引用这js文件就可以了。（animate.js、common.js）</p>
<h2 id="入口函数"><a href="#入口函数" class="headerlink" title="入口函数"></a>入口函数</h2><p>入口函数的好处：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 等待文档加载完成，保证能够获取到元素</span><br><span class="line"><span class="number">2.</span> 形成了一个沙箱，防止全局变量污染。</span><br></pre></td></tr></table></figure>

<p>两种写法：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//第一种写法</span></span><br><span class="line">$(<span class="built_in">document</span>).ready(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">&#125;);</span><br><span class="line"><span class="comment">//第二种写法</span></span><br><span class="line">$(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>jQuery入口函数与js入口函数的对比</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>JavaScript的入口函数要等到页面中所有资源（包括图片、文件）加载完成才开始执行。</span><br><span class="line"><span class="number">2.</span>jQuery的入口函数只会等待文档树加载完成就开始执行，并不会等待图片、文件的加载。</span><br><span class="line"></span><br><span class="line"><span class="comment">// 图片资源加载对比</span></span><br><span class="line">&lt;img src=<span class="string">"http://img.daimg.com/uploads/allimg/160324/1-160324232117.jpg"</span>&gt;</span><br><span class="line">&lt;img src=<span class="string">"http://img.daimg.com/uploads/allimg/160318/1-16031P01P0.jpg"</span>&gt;</span><br><span class="line">&lt;img src=<span class="string">"http://img.daimg.com/uploads/allimg/160318/1-16031P01332.jpg"</span>&gt;</span><br><span class="line">&lt;img src=<span class="string">"http://img.daimg.com/uploads/allimg/160608/1-16060R35630.jpg"</span> alt=<span class="string">""</span>&gt;</span><br><span class="line">&lt;img src=<span class="string">"http://img.daimg.com/uploads/allimg/160531/1-160531224303.jpg"</span> alt=<span class="string">""</span>&gt;</span><br></pre></td></tr></table></figure>



<h2 id="jQuery使用步骤"><a href="#jQuery使用步骤" class="headerlink" title="jQuery使用步骤"></a>jQuery使用步骤</h2><ol>
<li>引包（引入js文件）</li>
</ol>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"jquery-1.11.1.js"</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>

<ol start="2">
<li>写上入口函数</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="built_in">document</span>).ready(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 或者</span></span><br><span class="line">$(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    </span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<ol start="3">
<li>在入口函数内部实现功能</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="string">"#btnShowDiv"</span>).click(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">$(<span class="string">"div"</span>).show(<span class="number">1000</span>);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>



<h2 id="jQuery对象与DOM对象-重点"><a href="#jQuery对象与DOM对象-重点" class="headerlink" title="jQuery对象与DOM对象(重点)"></a>jQuery对象与DOM对象(重点)</h2><p>基本概念：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> DOM对象：使用JavaScript中的方法获取页面中的元素返回的对象就是dom对象。</span><br><span class="line"><span class="number">2.</span> jQuery对象：jquery对象就是使用jquery的方法获取页面中的元素返回的对象就是jQuery对象。</span><br><span class="line"><span class="number">3.</span> jQuery对象其实就是DOM对象的包装集（包装了DOM对象的集合（伪数组））</span><br></pre></td></tr></table></figure>

<p>jQuery对象与DOM对象的区别：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> DOM对象与jQuery对象的方法不能混用。</span><br><span class="line"><span class="number">2.</span> DOM对象可以和jQuery对象相互转化</span><br></pre></td></tr></table></figure>

<p>DOM对象转换成jQuery对象：【联想记忆：花钱】</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> $obj = $(domObj);</span><br><span class="line"><span class="comment">// $(document).ready(function()&#123;&#125;); 就是典型的DOM对象转jQuery对象</span></span><br></pre></td></tr></table></figure>

<p>jQuery对象转换成DOM对象：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> $li = $(“li”);</span><br><span class="line"><span class="comment">//第一种方法（推荐使用）</span></span><br><span class="line">$li[<span class="number">0</span>]</span><br><span class="line"><span class="comment">//第二种方法</span></span><br><span class="line">$li.get(<span class="number">0</span>)</span><br></pre></td></tr></table></figure>

<p>【练习：隔行变色案例.html】</p>
<h1 id="选择器"><a href="#选择器" class="headerlink" title="选择器"></a>选择器</h1><h2 id="什么是jQuery选择器"><a href="#什么是jQuery选择器" class="headerlink" title="什么是jQuery选择器"></a>什么是jQuery选择器</h2><p>jQuery选择器是jQuery为我们提供的一组方法，让我们更加方便的获取到页面中的元素。注意：jQuery选择器返回的是jQuery对象。</p>
<p>jQuery选择器有很多，基本兼容了CSS1到CSS3所有的选择器，并且jQuery还添加了很多更加复杂的选择器。【查看jQuery文档】</p>
<p>jQuery选择器虽然很多，但是选择器之间可以相互替代，就是说获取一个元素，你会有很多种方法获取到。所以我们平时真正能用到的只是少数的最常用的选择器。</p>
<h2 id="css选择器"><a href="#css选择器" class="headerlink" title="css选择器"></a>css选择器</h2><blockquote>
<p>jQuery完全兼容css选择器</p>
</blockquote>
<table>
<thead>
<tr>
<th>名称</th>
<th>用法</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td>ID选择器</td>
<td>$(“#id”);</td>
<td align="left">获取指定ID的元素</td>
</tr>
<tr>
<td>类选择器</td>
<td>$(“.class”);</td>
<td align="left">获取同一类class的元素</td>
</tr>
<tr>
<td>标签选择器</td>
<td>$(“div”);</td>
<td align="left">获取同一类标签的所有元素</td>
</tr>
<tr>
<td>并集选择器</td>
<td>$(“div,p,li”);</td>
<td align="left">使用逗号分隔，只要符合条件之一就可。</td>
</tr>
<tr>
<td>交集选择器</td>
<td>$(“div.redClass”);</td>
<td align="left">获取class为redClass的div元素</td>
</tr>
<tr>
<td>子代选择器</td>
<td>$(“ul&gt;li”);</td>
<td align="left">使用&gt;号，获取儿子层级的元素，注意，并不会获取孙子层级的元素</td>
</tr>
<tr>
<td>后代选择器</td>
<td>$(“ul li”);</td>
<td align="left">使用空格，代表后代选择器，获取ul下的所有li元素，包括孙子等</td>
</tr>
</tbody></table>
<blockquote>
<p>跟CSS的选择器一模一样。</p>
</blockquote>
<h2 id="过滤选择器"><a href="#过滤选择器" class="headerlink" title="过滤选择器"></a>过滤选择器</h2><blockquote>
<p>这类选择器都带冒号:</p>
</blockquote>
<table>
<thead>
<tr>
<th>名称</th>
<th>用法</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td>:eq（index）</td>
<td>$(“li:eq(2)”).css(“color”, ”red”);</td>
<td align="left">获取到的li元素中，选择索引号为2的元素，索引号index从0开始。</td>
</tr>
<tr>
<td>:odd</td>
<td>$(“li:odd”).css(“color”, ”red”);</td>
<td align="left">获取到的li元素中，选择索引号为奇数的元素</td>
</tr>
<tr>
<td>:even</td>
<td>$(“li:even”).css(“color”, ”red”);</td>
<td align="left">获取到的li元素中，选择索引号为偶数的元素</td>
</tr>
<tr>
<td>:first</td>
<td>$(“li:first”).css(“color”, ”red”);</td>
<td align="left">获取到的li元素中的第一个</td>
</tr>
<tr>
<td>:last</td>
<td>$(“li:last”).css(“color”, ”red”);</td>
<td align="left">获取到的li元素中的最后一个</td>
</tr>
</tbody></table>
<p>【案例：隔行变色】</p>
<h2 id="筛选选择器-方法"><a href="#筛选选择器-方法" class="headerlink" title="筛选选择器(方法)"></a>筛选选择器(方法)</h2><blockquote>
<p>筛选选择器的功能与过滤选择器有点类似，但是用法不一样，<code>筛选选择器</code>主要是方法。</p>
</blockquote>
<table>
<thead>
<tr>
<th>名称</th>
<th>用法</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td>children(selector)</td>
<td>$(“ul”).children(“li”)</td>
<td align="left">获取当前元素的所有子元素中的li元素</td>
</tr>
<tr>
<td>find(selector)</td>
<td>$(“ul”).find(“li”);</td>
<td align="left">获取当前元素中的后代元素中的li元素</td>
</tr>
<tr>
<td>siblings(selector)</td>
<td>$(“#first”).siblings(“li”);</td>
<td align="left">查找兄弟节点，不包括自己本身。</td>
</tr>
<tr>
<td>parent()</td>
<td>$(“#first”).parent();</td>
<td align="left">查找父亲</td>
</tr>
<tr>
<td>eq(index)</td>
<td>$(“li”).eq(2);</td>
<td align="left">相当于<code>$(“li:eq(2)”)</code>,index从0开始</td>
</tr>
<tr>
<td>next()</td>
<td>$(“li”).next()</td>
<td align="left">找下一个兄弟</td>
</tr>
<tr>
<td>prev()</td>
<td>$(“li”).prev()</td>
<td align="left">找上一次兄弟</td>
</tr>
</tbody></table>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h1 id="其他补充"><a href="#其他补充" class="headerlink" title="其他补充"></a>其他补充</h1><h2 id="mouseover-与-mouseenter"><a href="#mouseover-与-mouseenter" class="headerlink" title="mouseover 与 mouseenter"></a>mouseover 与 mouseenter</h2><blockquote>
<p>mouseover 和 mouseoverenter 都有鼠标经过的意思，但是在注册鼠标经过事件的时候，推荐使用<code>mouseenter</code></p>
</blockquote>
<p><a href="http://www.w3school.com.cn/tiy/t.asp?f=jquery_event_mouseenter_mouseover" target="_blank" rel="noopener">mouseenter 与 mouseover 的不同</a></p>
<ol>
<li>mouseover与mouseout是一对事件，当鼠标经过当前元素或者当前元素的子元素的时候，mouseover事件都会触发【事件冒泡】。</li>
<li>mouseenter 与mouseleave是一对事件，只有当鼠标经过当前元素时，事件会触发，鼠标经过子元素，mousenter事件是不会触发的。</li>
</ol>
<h2 id="index方法"><a href="#index方法" class="headerlink" title="index方法"></a>index方法</h2><blockquote>
<p><code>index()</code>方法返回的是当前元素在所有兄弟元素里面的索引。</p>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">ul</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"#"</span>&gt;</span>我是链接<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"#"</span>&gt;</span>我是链接<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"#"</span>&gt;</span>我是链接<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"#"</span>&gt;</span>我是链接<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"#"</span>&gt;</span>我是链接<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"#"</span>&gt;</span>我是链接<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"#"</span>&gt;</span>我是链接<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"#"</span>&gt;</span>我是链接<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">li</span>&gt;</span><span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">"#"</span>&gt;</span>我是链接<span class="tag">&lt;/<span class="name">a</span>&gt;</span><span class="tag">&lt;/<span class="name">li</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">ul</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p><strong>当碰到这种结构的时候，推荐给li注册事件，这样通过index方法才能获取到正确的索引值。</strong></p>
<h2 id="区分jQuery与Javascript"><a href="#区分jQuery与Javascript" class="headerlink" title="区分jQuery与Javascript"></a>区分jQuery与Javascript</h2><p>JavaScript是一门编程语言，jQuery仅仅是用JavaScript实现的一个JavaScript库，目的是简化我们的开发。</p>
<p><img src="/blog/2017/05/05/JQuery/JQuery/1.png" alt></p>
<h1 id="jQuery操作样式"><a href="#jQuery操作样式" class="headerlink" title="jQuery操作样式"></a>jQuery操作样式</h1><h2 id="css操作"><a href="#css操作" class="headerlink" title="css操作"></a>css操作</h2><blockquote>
<p>功能：设置或者修改样式，操作的是style属性。</p>
</blockquote>
<blockquote>
<p>操作单个样式</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//name：需要设置的样式名称</span></span><br><span class="line"><span class="comment">//value：对应的样式值</span></span><br><span class="line">css(name, value);</span><br><span class="line"><span class="comment">//使用案例</span></span><br><span class="line">$(<span class="string">"#one"</span>).css(<span class="string">"background"</span>,<span class="string">"gray"</span>);<span class="comment">//将背景色修改为灰色</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>设置多个样式</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//参数是一个对象，对象中包含了需要设置的样式名和样式值</span></span><br><span class="line">css(obj);</span><br><span class="line"><span class="comment">//使用案例</span></span><br><span class="line">$(<span class="string">"#one"</span>).css(&#123;</span><br><span class="line">    <span class="string">"background"</span>:<span class="string">"gray"</span>,</span><br><span class="line">    <span class="string">"width"</span>:<span class="string">"400px"</span>,</span><br><span class="line">    <span class="string">"height"</span>:<span class="string">"200px"</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>获取样式</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//name:需要获取的样式名称</span></span><br><span class="line">css(name);</span><br><span class="line"><span class="comment">//案例</span></span><br><span class="line">$(<span class="string">"div"</span>).css(<span class="string">"background-color"</span>);</span><br></pre></td></tr></table></figure>

<p>注意：获取样式操作只会返回第一个元素对应的样式值。</p>
<p>隐式迭代：</p>
<ol>
<li>设置操作的时候，如果是多个元素，那么给所有的元素设置相同的值</li>
<li>获取操作的时候，如果是多个元素，那么只会返回第一个元素的值。</li>
</ol>
<h2 id="class操作"><a href="#class操作" class="headerlink" title="class操作"></a>class操作</h2><blockquote>
<p>添加样式类</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//name：需要添加的样式类名，注意参数不要带点.</span></span><br><span class="line">addClass(name);</span><br><span class="line"><span class="comment">//例子,给所有的div添加one的样式。</span></span><br><span class="line">$(“div”).addClass(“one”);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>移除样式类</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//name:需要移除的样式类名</span></span><br><span class="line">removeClass(“name”);</span><br><span class="line"><span class="comment">//例子，移除div中one的样式类名</span></span><br><span class="line">$(“div”).removeClass(“one”);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>判断是否有某个样式类</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//name: 用于判断的样式类名，返回值为true false</span></span><br><span class="line">hasClass(name)</span><br><span class="line"><span class="comment">//例子，判断是否有one的样式类</span></span><br><span class="line">$(“div”).hasClass(“one”);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>切换样式类</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//name:需要切换的样式类名，如果有，移除该样式，如果没有，添加该样式。</span></span><br><span class="line">toggleClass(name);</span><br><span class="line"><span class="comment">//例子</span></span><br><span class="line">$(“div”).toggleClass(“one”);</span><br></pre></td></tr></table></figure>

<p>【案例：tab栏切换案例.html】</p>
<h1 id="jQuery操作属性"><a href="#jQuery操作属性" class="headerlink" title="jQuery操作属性"></a>jQuery操作属性</h1><h2 id="attr操作"><a href="#attr操作" class="headerlink" title="attr操作"></a>attr操作</h2><blockquote>
<p>设置单个属性</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//第一个参数：需要设置的属性名</span></span><br><span class="line"><span class="comment">//第二个参数：对应的属性值</span></span><br><span class="line">attr(name, value);</span><br><span class="line"><span class="comment">//用法举例</span></span><br><span class="line">$(“img”).attr(“title”,”哎哟，不错哦”);</span><br><span class="line">$(“img”).attr(“alt”,“哎哟，不错哦”);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>设置多个属性</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//参数是一个对象，包含了需要设置的属性名和属性值</span></span><br><span class="line">attr(obj)</span><br><span class="line"><span class="comment">//用法举例</span></span><br><span class="line">$(<span class="string">"img"</span>).attr(&#123;</span><br><span class="line">    title:<span class="string">"哎哟，不错哦"</span>,</span><br><span class="line">    alt:<span class="string">"哎哟，不错哦"</span>,</span><br><span class="line">    style:<span class="string">"opacity:.5"</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>获取属性</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//传需要获取的属性名称，返回对应的属性值</span></span><br><span class="line">attr(name)</span><br><span class="line"><span class="comment">//用法举例</span></span><br><span class="line"><span class="keyword">var</span> oTitle = $(<span class="string">"img"</span>).attr(<span class="string">"title"</span>);</span><br><span class="line">alert(oTitle);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>移除属性</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//参数：需要移除的属性名，</span></span><br><span class="line">removeAttr(name);</span><br><span class="line"><span class="comment">//用法举例</span></span><br><span class="line">$(<span class="string">"img"</span>).removeAttr(<span class="string">"title"</span>);</span><br></pre></td></tr></table></figure>

<p>【案例：美女相册.html】</p>
<h2 id="prop操作"><a href="#prop操作" class="headerlink" title="prop操作"></a>prop操作</h2><blockquote>
<p>在jQuery1.6之后，对于checked、selected、disabled这类boolean类型的属性来说，不能用attr方法，只能用prop方法。</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//设置属性</span></span><br><span class="line">$(“input:checked”).prop(“checked”,<span class="literal">true</span>);</span><br><span class="line"><span class="comment">//获取属性</span></span><br><span class="line">$(“input:checked”).prop(“checked”);<span class="comment">//返回true或者false</span></span><br></pre></td></tr></table></figure>

<p>【案例：表格全选案例.html】</p>
<h1 id="jQuery动画"><a href="#jQuery动画" class="headerlink" title="jQuery动画"></a>jQuery动画</h1><blockquote>
<p>jquery提供了三组基本动画，这些动画都是标准的、有规律的效果，jquery还提供了自定义动画的功能。【演示动画例子】</p>
</blockquote>
<h2 id="三组基本动画"><a href="#三组基本动画" class="headerlink" title="三组基本动画"></a>三组基本动画</h2><blockquote>
<p>显示(show)与隐藏(hide)是一组动画：<br>滑入(slideUp)与滑出(slideDown)与切换(slideToggle)，效果与卷帘门类似<br>淡入(fadeIn)与淡出(fadeOut)与切换(fadeToggle)</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">show([speed], [easing], [callback]);</span><br><span class="line"><span class="comment">//speed(可选)：动画的执行时间</span></span><br><span class="line"> <span class="comment">//1.如果不传，就没有动画效果。如果是slide和fade系列，会默认为normal</span></span><br><span class="line"> <span class="comment">//2.毫秒值(比如1000),动画在1000毫秒执行完成(推荐)</span></span><br><span class="line">     <span class="comment">//3.固定字符串，slow(200)、normal(400)、fast(600)，如果传其他字符串，则默认为normal。</span></span><br><span class="line"><span class="comment">// easing(可选)： 动画效果，默认是swing，秋千，提供了一个linear 匀速的效果</span></span><br><span class="line"><span class="comment">//callback(可选):执行完动画后执行的回调函数</span></span><br></pre></td></tr></table></figure>

<p>【案例：下拉菜单动画版.html】<br>【案例：京东轮播图(呼吸灯).html】</p>
<h2 id="自定义动画"><a href="#自定义动画" class="headerlink" title="自定义动画"></a>自定义动画</h2><blockquote>
<p>animate: 自定义动画</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$(selector).animate(&#123;params&#125;,[speed],[easing],[callback]);</span><br><span class="line"><span class="comment">// &#123;params&#125;：要执行动画的CSS属性，带数字（必选）</span></span><br><span class="line"><span class="comment">// speed：执行动画时长（可选）</span></span><br><span class="line"><span class="comment">// easing: 执行效果，默认为swing（缓动）  可以是linear（匀速）</span></span><br><span class="line"><span class="comment">// callback：动画执行完后立即执行的回调函数（可选）</span></span><br></pre></td></tr></table></figure>



<h2 id="动画队列与停止动画"><a href="#动画队列与停止动画" class="headerlink" title="动画队列与停止动画"></a>动画队列与停止动画</h2><blockquote>
<p>在同一个元素上执行多个动画，那么对于这个动画来说，后面的动画会被放到动画队列中，等前面的动画执行完成了才会执行。</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//stop方法：停止动画效果</span></span><br><span class="line">stop(clearQueue, jumpToEnd);</span><br><span class="line"><span class="comment">//第一个参数：是否清除队列</span></span><br><span class="line"><span class="comment">//第二个参数：是否跳转到最终效果</span></span><br></pre></td></tr></table></figure>
<p>【案例：手风琴特效】【案例：音乐导航】</p>
<h1 id="jQuery节点操作"><a href="#jQuery节点操作" class="headerlink" title="jQuery节点操作"></a>jQuery节点操作</h1><h2 id="创建节点"><a href="#创建节点" class="headerlink" title="创建节点"></a>创建节点</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//$(htmlStr)</span></span><br><span class="line"><span class="comment">//htmlStr：html格式的字符串</span></span><br><span class="line">$(<span class="string">"&lt;span&gt;这是一个span元素&lt;/span&gt;"</span>);</span><br></pre></td></tr></table></figure>

<h2 id="添加节点"><a href="#添加节点" class="headerlink" title="添加节点"></a>添加节点</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// append  appendTo   都是添加到元素内部的最后面</span></span><br><span class="line"><span class="comment">// prepend prependTo  都是添加到元素内部的最前面</span></span><br><span class="line"><span class="comment">// before  添加到元素前面，做兄弟</span></span><br><span class="line"><span class="comment">// after    添加到元素后面，做兄弟</span></span><br></pre></td></tr></table></figure>

<p>【案例：城市选择案例.html】</p>
<h2 id="清空节点与删除节点"><a href="#清空节点与删除节点" class="headerlink" title="清空节点与删除节点"></a>清空节点与删除节点</h2><blockquote>
<p>empty：清空指定节点的所有元素，自身保留(清理门户)</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$(“div”).empty();<span class="comment">//清空div的所有内容</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>remove：相比于empty，自身也删除（自杀）</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$(“div”).remove();</span><br></pre></td></tr></table></figure>

<h2 id="克隆节点"><a href="#克隆节点" class="headerlink" title="克隆节点"></a>克隆节点</h2><blockquote>
<p>作用：复制匹配的元素</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 复制$(selector)所匹配到的元素（深度复制）</span></span><br><span class="line"><span class="comment">// cloneNode(true)</span></span><br><span class="line"><span class="comment">// 返回值为复制的新元素，和原来的元素没有任何关系了。即修改新元素，不会影响到原来的元素。</span></span><br><span class="line">$(selector).clone();</span><br></pre></td></tr></table></figure>
<h1 id="jQuery特殊属性操作"><a href="#jQuery特殊属性操作" class="headerlink" title="jQuery特殊属性操作"></a>jQuery特殊属性操作</h1><h2 id="val方法"><a href="#val方法" class="headerlink" title="val方法"></a>val方法</h2><blockquote>
<p>val方法用于设置和获取表单元素的值，例如input、textarea的值</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//设置值</span></span><br><span class="line">$(<span class="string">"#name"</span>).val(“张三”);</span><br><span class="line"><span class="comment">//获取值</span></span><br><span class="line">$(<span class="string">"#name"</span>).val();</span><br></pre></td></tr></table></figure>

<p>【案例：微博发布】 </p>
<h2 id="html方法与text方法"><a href="#html方法与text方法" class="headerlink" title="html方法与text方法"></a>html方法与text方法</h2><blockquote>
<p>html方法相当于innerHTML  text方法相当于innerText</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//设置内容</span></span><br><span class="line">$(“div”).html(“&lt;span&gt;这是一段内容&lt;<span class="regexp">/span&gt;”);</span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/获取内容</span></span><br><span class="line"><span class="regexp">$(“div”).html()</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/设置内容</span></span><br><span class="line"><span class="regexp">$(“div”).text(“&lt;span&gt;这是一段内容&lt;/</span>span&gt;”);</span><br><span class="line"><span class="comment">//获取内容</span></span><br><span class="line">$(“div”).text()</span><br></pre></td></tr></table></figure>
<p>区别：html方法会识别html标签，text方法会将内容直接当成字符串，并不会识别html标签。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">empty() 和 html() 方法都可以清空内容,但推荐使用empty方法清空元素里的内容</span><br><span class="line"></span><br><span class="line">$(“div”).empty();<span class="comment">//清空div的所有内容（推荐使用，会清除子元素上绑定的事件）</span></span><br><span class="line">$(“div”).html(<span class="string">""</span>);<span class="comment">//使用html方法来清空元素，不推荐使用，会造成内存泄漏，绑定的事件不会被清除。</span></span><br></pre></td></tr></table></figure>



<h2 id="width方法与height方法"><a href="#width方法与height方法" class="headerlink" title="width方法与height方法"></a>width方法与height方法</h2><blockquote>
<p>设置或者获取高度</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//带参数表示设置高度</span></span><br><span class="line">$(“img”).height(<span class="number">200</span>);</span><br><span class="line"><span class="comment">//不带参数获取高度</span></span><br><span class="line">$(“img”).height();</span><br></pre></td></tr></table></figure>

<p>获取网页的可视区宽高</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//获取可视区宽度</span></span><br><span class="line">$(<span class="built_in">window</span>).width();</span><br><span class="line"><span class="comment">//获取可视区高度</span></span><br><span class="line">$(<span class="built_in">window</span>).height();</span><br></pre></td></tr></table></figure>

<h2 id="scrollTop与scrollLeft"><a href="#scrollTop与scrollLeft" class="headerlink" title="scrollTop与scrollLeft"></a>scrollTop与scrollLeft</h2><blockquote>
<p>设置或者获取垂直滚动条的位置</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//获取页面被卷曲的高度</span></span><br><span class="line">$(<span class="built_in">window</span>).scrollTop();</span><br><span class="line"><span class="comment">//获取页面被卷曲的宽度</span></span><br><span class="line">$(<span class="built_in">window</span>).scrollLeft();</span><br></pre></td></tr></table></figure>

<p>【案例：仿腾讯固定菜单栏案例】【案例：小火箭返航案例】</p>
<h1 id="jQuery事件机制"><a href="#jQuery事件机制" class="headerlink" title="jQuery事件机制"></a>jQuery事件机制</h1><blockquote>
<p>JavaScript中已经学习过了事件，但是jQuery对JavaScript事件进行了封装，增加并扩展了事件处理机制。jQuery不仅提供了更加优雅的事件处理语法，而且极大的增强了事件的处理能力。</p>
</blockquote>
<h2 id="jQuery事件发展历程-了解"><a href="#jQuery事件发展历程-了解" class="headerlink" title="jQuery事件发展历程(了解)"></a>jQuery事件发展历程(了解)</h2><p>简单事件绑定&gt;&gt;bind事件绑定&gt;&gt;delegate事件绑定&gt;&gt;on事件绑定(推荐)</p>
<blockquote>
<p>简单事件注册</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">click(handler)单击事件</span><br><span class="line">mouseenter(handler)鼠标进入事件</span><br><span class="line">mouseleave(handler)鼠标离开事件</span><br></pre></td></tr></table></figure>
<p>缺点：不能同时注册多个事件</p>
<blockquote>
<p>bind方式注册事件</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//第一个参数：事件类型</span></span><br><span class="line"><span class="comment">//第二个参数：事件处理程序</span></span><br><span class="line">$(<span class="string">"p"</span>).bind(<span class="string">"click mouseenter"</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="comment">//事件响应方法</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>缺点：不支持动态事件绑定</p>
<blockquote>
<p>delegate注册委托事件</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 第一个参数：selector，要绑定事件的元素</span></span><br><span class="line"><span class="comment">// 第二个参数：事件类型</span></span><br><span class="line"><span class="comment">// 第三个参数：事件处理函数</span></span><br><span class="line">$(<span class="string">".parentBox"</span>).delegate(<span class="string">"p"</span>, <span class="string">"click"</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="comment">//为 .parentBox下面的所有的p标签绑定事件</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p>缺点：只能注册委托事件，因此注册时间需要记得方法太多了</p>
<blockquote>
<p>on注册事件</p>
</blockquote>
<h2 id="on注册事件-重点"><a href="#on注册事件-重点" class="headerlink" title="on注册事件(重点)"></a>on注册事件(重点)</h2><blockquote>
<p>jQuery1.7之后，jQuery用on统一了所有事件的处理方法。</p>
<p>最现代的方式，强烈建议使用。</p>
</blockquote>
<p>on注册简单事件</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 表示给$(selector)绑定事件，并且由自己触发，不支持动态绑定。</span></span><br><span class="line">$(selector).on( <span class="string">"click"</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;&#125;);</span><br></pre></td></tr></table></figure>

<p>on注册委托事件</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 表示给$(selector)绑定代理事件，当必须是它的内部元素span才能触发这个事件，支持动态绑定</span></span><br><span class="line">$(selector).on( <span class="string">"click"</span>,“span”, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;&#125;);</span><br></pre></td></tr></table></figure>

<p>on注册事件的语法：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 第一个参数：events，绑定事件的名称可以是由空格分隔的多个事件（标准事件或者自定义事件）</span></span><br><span class="line"><span class="comment">// 第二个参数：selector, 执行事件的后代元素（可选），如果没有后代元素，那么事件将有自己执行。</span></span><br><span class="line"><span class="comment">// 第三个参数：data，传递给处理函数的数据，事件触发的时候通过event.data来使用（不常使用）</span></span><br><span class="line"><span class="comment">// 第四个参数：handler，事件处理函数</span></span><br><span class="line">$(selector).on(events[,selector][,data],handler);</span><br></pre></td></tr></table></figure>

<h2 id="事件解绑"><a href="#事件解绑" class="headerlink" title="事件解绑"></a>事件解绑</h2><blockquote>
<p>unbind方式（不用）</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$(selector).unbind(); <span class="comment">//解绑所有的事件</span></span><br><span class="line">$(selector).unbind(<span class="string">"click"</span>); <span class="comment">//解绑指定的事件</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>undelegate方式（不用）</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$( selector ).undelegate(); <span class="comment">//解绑所有的delegate事件</span></span><br><span class="line">$( selector).undelegate( “click” ); <span class="comment">//解绑所有的click事件</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>off方式（推荐）</p>
</blockquote>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 解绑匹配元素的所有事件</span></span><br><span class="line">$(selector).off();</span><br><span class="line"><span class="comment">// 解绑匹配元素的所有click事件</span></span><br><span class="line">$(selector).off(<span class="string">"click"</span>);</span><br></pre></td></tr></table></figure>

<h2 id="触发事件"><a href="#触发事件" class="headerlink" title="触发事件"></a>触发事件</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$(selector).click(); <span class="comment">//触发 click事件</span></span><br><span class="line">$(selector).trigger(<span class="string">"click"</span>);</span><br></pre></td></tr></table></figure>

<h2 id="jQuery事件对象"><a href="#jQuery事件对象" class="headerlink" title="jQuery事件对象"></a>jQuery事件对象</h2><p>jQuery事件对象其实就是js事件对象的一个封装，处理了兼容性。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//screenX和screenY对应屏幕最左上角的值</span></span><br><span class="line"><span class="comment">//clientX和clientY距离页面左上角的位置（忽视滚动条）</span></span><br><span class="line"><span class="comment">//pageX和pageY距离页面最顶部的左上角的位置（会计算滚动条的距离）</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//event.keyCode按下的键盘代码</span></span><br><span class="line"><span class="comment">//event.data存储绑定事件时传递的附加数据</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//event.stopPropagation()阻止事件冒泡行为</span></span><br><span class="line"><span class="comment">//event.preventDefault()阻止浏览器默认行为</span></span><br><span class="line"><span class="comment">//return false 既能阻止事件冒泡，又能阻止浏览器默认行为。</span></span><br></pre></td></tr></table></figure>

<p>【案例：钢琴版导航（加强）.html】【案例：弹幕效果】</p>
<h1 id="jQuery补充知识点"><a href="#jQuery补充知识点" class="headerlink" title="jQuery补充知识点"></a>jQuery补充知识点</h1><h2 id="隐式迭代"><a href="#隐式迭代" class="headerlink" title="隐式迭代"></a>隐式迭代</h2><h3 id="基本概念"><a href="#基本概念" class="headerlink" title="基本概念"></a>基本概念</h3><blockquote>
<p>隐式迭代：jQuery在设置属性时会自动的遍历，因此我们不需要再遍历</p>
</blockquote>
<ol>
<li>jQuery在执行设置性操作时，会给所有的元素都设置上相同的值。</li>
<li>jQuery在执行获取性操作时，只会返回第一个元素对应的值。</li>
<li>如果想要给每一个元素都设置不同的值，需要手动进行遍历jQuery对象。</li>
</ol>
<h3 id="each方法"><a href="#each方法" class="headerlink" title="each方法"></a>each方法</h3><blockquote>
<p>遍历jQuery对象集合，为每个匹配的元素执行一个函数</p>
</blockquote>
<p>语法：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 参数一表示当前元素在所有匹配元素中的索引号</span></span><br><span class="line"><span class="comment">// 参数二表示当前元素, 在function中this也表示当前元素。</span></span><br><span class="line">$(selector).each(<span class="function"><span class="keyword">function</span>(<span class="params">index,element</span>)</span>&#123;&#125;);</span><br></pre></td></tr></table></figure>

<h2 id="链式编程"><a href="#链式编程" class="headerlink" title="链式编程"></a>链式编程</h2><blockquote>
<p>链式编程的原理：设置性操作会返回一个jQuery对象，因此可以继续调用jQuery的方法。</p>
</blockquote>
<ol>
<li>设置操作的时候，可以使用链式编程。</li>
<li>获取操作的时候，无法使用链式编程。</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">end(); <span class="comment">// 上一次返回的jq对象</span></span><br></pre></td></tr></table></figure>

<p>【案例：五角星评分案例.html】</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">prevAll();<span class="comment">//获取前面所有的兄弟元素</span></span><br><span class="line">nextAll();<span class="comment">//获取后面所有的兄弟元素</span></span><br><span class="line">siblings();<span class="comment">//获取所有的兄弟元素</span></span><br><span class="line">prev();<span class="comment">//获取前一个兄弟</span></span><br><span class="line">next();<span class="comment">//获取后一个兄弟。</span></span><br></pre></td></tr></table></figure>

<h1 id="jQuery插件"><a href="#jQuery插件" class="headerlink" title="jQuery插件"></a>jQuery插件</h1><blockquote>
<p>插件：jquery不可能包含所有的功能，我们可以通过插件扩展jquery的功能。</p>
</blockquote>
<p>jQuery有着丰富的插件，使用这些插件能给jQuery提供一些额外的功能。</p>
<h2 id="使用插件"><a href="#使用插件" class="headerlink" title="使用插件"></a>使用插件</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 引入jQuery文件</span><br><span class="line"><span class="number">2.</span> 引入插件（如果有用到css的话，需要引入css）</span><br><span class="line"><span class="number">3.</span> 使用插件</span><br></pre></td></tr></table></figure>

<p>常用插件的使用</p>
<ul>
<li>jquery.color.js的使用<ul>
<li><a href="https://github.com/jquery/jquery-color" target="_blank" rel="noopener">https://github.com/jquery/jquery-color</a></li>
</ul>
</li>
</ul>
<ul>
<li>jquery.lazyload.js的使用<ul>
<li><a href="https://github.com/tuupola/jquery_lazyload" target="_blank" rel="noopener">https://github.com/tuupola/jquery_lazyload</a></li>
</ul>
</li>
</ul>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/JQuery/" rel="tag"># JQuery</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2017/04/03/javaScript/%E5%87%BD%E6%95%B0/" rel="prev" title="函数基础">
      <i class="fa fa-chevron-left"></i> 函数基础
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2017/07/04/javaScript/%E5%B8%B8%E7%94%A8%E7%9A%84%E5%B0%8F%E6%96%B9%E6%B3%95/" rel="next" title="常用的小方法">
      常用的小方法 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#jQuery基本介绍"><span class="nav-text">jQuery基本介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#为什么要学jQuery"><span class="nav-text">为什么要学jQuery</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery初体验"><span class="nav-text">jQuery初体验</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#什么是jQuery"><span class="nav-text">什么是jQuery?</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#入口函数"><span class="nav-text">入口函数</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery使用步骤"><span class="nav-text">jQuery使用步骤</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery对象与DOM对象-重点"><span class="nav-text">jQuery对象与DOM对象(重点)</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#选择器"><span class="nav-text">选择器</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#什么是jQuery选择器"><span class="nav-text">什么是jQuery选择器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#css选择器"><span class="nav-text">css选择器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#过滤选择器"><span class="nav-text">过滤选择器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#筛选选择器-方法"><span class="nav-text">筛选选择器(方法)</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#其他补充"><span class="nav-text">其他补充</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#mouseover-与-mouseenter"><span class="nav-text">mouseover 与 mouseenter</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#index方法"><span class="nav-text">index方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#区分jQuery与Javascript"><span class="nav-text">区分jQuery与Javascript</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#jQuery操作样式"><span class="nav-text">jQuery操作样式</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#css操作"><span class="nav-text">css操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#class操作"><span class="nav-text">class操作</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#jQuery操作属性"><span class="nav-text">jQuery操作属性</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#attr操作"><span class="nav-text">attr操作</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#prop操作"><span class="nav-text">prop操作</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#jQuery动画"><span class="nav-text">jQuery动画</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#三组基本动画"><span class="nav-text">三组基本动画</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#自定义动画"><span class="nav-text">自定义动画</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#动画队列与停止动画"><span class="nav-text">动画队列与停止动画</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#jQuery节点操作"><span class="nav-text">jQuery节点操作</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#创建节点"><span class="nav-text">创建节点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#添加节点"><span class="nav-text">添加节点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#清空节点与删除节点"><span class="nav-text">清空节点与删除节点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#克隆节点"><span class="nav-text">克隆节点</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#jQuery特殊属性操作"><span class="nav-text">jQuery特殊属性操作</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#val方法"><span class="nav-text">val方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#html方法与text方法"><span class="nav-text">html方法与text方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#width方法与height方法"><span class="nav-text">width方法与height方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#scrollTop与scrollLeft"><span class="nav-text">scrollTop与scrollLeft</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#jQuery事件机制"><span class="nav-text">jQuery事件机制</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery事件发展历程-了解"><span class="nav-text">jQuery事件发展历程(了解)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#on注册事件-重点"><span class="nav-text">on注册事件(重点)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#事件解绑"><span class="nav-text">事件解绑</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#触发事件"><span class="nav-text">触发事件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery事件对象"><span class="nav-text">jQuery事件对象</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#jQuery补充知识点"><span class="nav-text">jQuery补充知识点</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#隐式迭代"><span class="nav-text">隐式迭代</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#基本概念"><span class="nav-text">基本概念</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#each方法"><span class="nav-text">each方法</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#链式编程"><span class="nav-text">链式编程</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#jQuery插件"><span class="nav-text">jQuery插件</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#使用插件"><span class="nav-text">使用插件</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="大春哥"
      src="/blog/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">大春哥</p>
  <div class="site-description" itemprop="description">IT</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">35</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">11</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
          
        <span class="site-state-item-count">17</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">大春哥</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  




  
<script src="/blog/js/local-search.js"></script>













  

  

</body>
</html>
